package letsjava.utils;

import java.util.*;

public class NSDebug {
	public static void printDebug() {
		System.out.println(debugStr());
	}

	public static String debugStr() {
		StringBuffer a = new StringBuffer();
		Throwable th = new Throwable();
		StackTraceElement[] frames = th.getStackTrace();
		for (StackTraceElement ste : frames) {
			a.append(ste.toString() + "\n");
		}
		return a.toString();
	}

	public static int fabo(int n) {
		System.out.println("fabo(" + n + ")");
		Throwable th = new Throwable();
		StackTraceElement[] frames = th.getStackTrace();
		for (StackTraceElement ste : frames) {
			System.out.println(ste);
		}
		int re = 0;
		if (n == 1) {
			re = 1;
		} else {
			re = n * fabo(n - 1);
		}
		System.out.println("return " + re);
		return re;
	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.print("please input n: ");
		int n = scanner.nextInt();
		fabo(n);

		/*
		 * System.out.println(fabo(7)); Map<Thread, StackTraceElement[]> map =
		 * Thread.getAllStackTraces(); for(Thread t: map.keySet()){
		 * //System.out.print(t.getClass()+"/");
		 * //System.out.print(t.getName()); System.out.print(t.toString());
		 * System.out.println(); }
		 */

	}
}
